package com.moore.controller;

import com.moore.bean.Apartment;
import com.moore.bean.ApartmentForm;
import com.moore.dto.ResponseData;
import com.moore.service.ApartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

import java.util.List;

import static com.moore.utils.Logger.toLog;

@Controller
@RequestMapping("/apartment")
public class ApartmentController {

    @Autowired
    private ApartmentService apartmentService;

    @RequestMapping("/confirmAdd")
    @ResponseBody
    public ResponseData confirmAddApartment(@RequestBody ApartmentForm apartmentForm){
        toLog("正在确认批量添加套房");
        return apartmentService.confirmAddApartment(apartmentForm);
    }

    @RequestMapping("/add")
    @ResponseBody
    public ResponseData addApartment(@RequestBody ApartmentForm apartmentForm){
        toLog("正在批量添加套房");
        return apartmentService.addApartment(apartmentForm);
    }

    @RequestMapping("/addAn")
    @ResponseBody
    public ResponseData addAnApartment(@RequestBody Apartment apartment){
        toLog("正在添加/修改套房");
        return apartmentService.addAnApartment(apartment);
    }

    @RequestMapping("/building")
    @ResponseBody
    public ResponseData getBuildings(@RequestBody Apartment apartment){
        toLog("正在获取所有楼栋");
        return apartmentService.getBuildings(apartment);
    }

    @RequestMapping("/query")
    @ResponseBody
    public ResponseData queryApartment(@RequestBody Apartment apartment, HttpServletRequest request){
        toLog("正在查询套房");
        return apartmentService.getApartments(apartment, request);
    }

    @RequestMapping("/updateStatus")
    @ResponseBody
    public ResponseData updateApartmentStatus(@RequestBody Apartment apartment){
        toLog("正在更新套房状态");
        return apartmentService.updateApartmentStatus(apartment.getStatus(),apartment.getId());
    }

    @RequestMapping("/batchPublish")
    @ResponseBody
    public ResponseData batchPublish(@RequestBody List<Apartment> apartments){
        toLog("正在批量发布套房");
        return apartmentService.batchPublishApartments(apartments);
    }

    @RequestMapping("/layout")
    @ResponseBody
    public ResponseData getLayout(@RequestBody Apartment apartment){
        toLog("正在获取套房布局");
        return apartmentService.getApartmentsLayout(apartment.getAreaName(), apartment.getCommunityName());
    }

    @RequestMapping("/area")
    @ResponseBody
    public ResponseData getArea(@RequestBody Apartment apartment){
        toLog("正在获取套房面积");
        return apartmentService.getApartmentsArea(apartment.getAreaName(), apartment.getCommunityName());
    }

    @RequestMapping("/rent")
    @ResponseBody
    public ResponseData getRent(@RequestBody Apartment apartment){
        toLog("正在获取套房租金");
        return apartmentService.getApartmentsRent(apartment.getAreaName(), apartment.getCommunityName());
    }

    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData deleteApartment(@RequestBody List<Apartment> apartments){
        toLog("正在删除套房");
        return apartmentService.deleteApartment(apartments);
    }

    @RequestMapping("/reclaim")
    @ResponseBody
    public ResponseData reclaimApartment(@RequestBody List<Apartment> apartments){
        toLog("正在回收套房");
        return apartmentService.reclaimApartment(apartments);
    }
}
